<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>小米闪购定时器</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    ul {
      list-style: none;
    }

    #box {
      position: absolute;
      top: 50%;
      left: 50%;
      height: 50%;
      width: 80vw;
      transform: translate(-50%, -50%);
      height: 100px;
      display: flex;
      justify-content: center;
      cursor: pointer;
    }

    .item {
      flex: 1;
      text-align: center;
      height: 100%;
      line-height: 100px;
      background: #414141;
      color: #fff;
    }

    #box .active {
      background-color: #f1393a;
    }
  </style>
</head>

<body>
  <ul id="box">
    <li class="item active">
      <span>14:00</span>
      还剩 <span>20:30:30</span>
    </li>
    <li class="item">
      <span>15:00</span>
      还剩 <span>20:30:30</span>
    </li>
    <li class="item">
      <span>16:00</span>
      还剩 <span>20:30:30</span>
    </li>
    <li class="item">
      <span>17:00</span>
      还剩 <span>20:30:30</span>
    </li>
    <li class="item">
      <span>17:00</span>
      还剩 <span>20:30:30</span>
    </li>
  </ul>
  <script>
    // 用户输入数据 格式
    const DATE = ['2020-10-17 9:00', '2020-10-17 10:00', '2020-10-17 20:00', '2020-10-18 8:00', '2020-10-18 10:00'];



    // 逻辑处理部分
    ((window) => {
      let dateArr = [];
      let index = 0;
      let box = document.getElementById('box');

      for (let i = 0; i < DATE.length; i++) {
        dateArr.push(DATE[i].split(' '));
      }

      init()

      function init() {
        let str = '';
        for (let i = 0; i < dateArr.length; i++) {
          str += tmp(dateArr[i]);
        }
        box.innerHTML = str;
      }

      function tmp(date) {
        // let params = {
        //   date: ['2020-10-17', '9:00']
        // };
        return `
        <li class="item">
          <span>${date[1]}</span>
           <span>${toDay(date[0])}</span>
      </li>
        `;
      }

      function toDay(str) {
        let val = +new Date() - +new Date(str);
        return val < 86400000 && val > 0 ? '即将开始' : '明日开始';
      }
    })(window);

    // 分割字符串


  </script>
</body>

</html>